<?php

namespace App\Admin\Renderables;

use App\Admin\Controllers\StudentController;
use App\Models\Student;
use Dcat\Admin\Support\LazyRenderable;
use Dcat\Admin\Widgets\Card;

class StudentShowRenderable extends LazyRenderable
{
    public function render()
    {
        // 获取外部传递的参数
        $payload = $this->payload;
        
        $id = 0;
        if (isset($payload['xuegonghao'])) {
            $student = Student::findByXuegonghao($payload['xuegonghao']);
            if (!$student) {
                return '学生不存在';
            }
            $id = $student->id;
        }
        if (isset($payload['gid'])) {
            $student = Student::findByGid($payload['gid']);
            if (!$student) {
                return '学生不存在';
            }
            $id = $student->id;
        }
        if (isset($payload['id'])) {
            $id = $payload['id'];
        }
        $content = (new StudentController)->detail($id, 'dialog');
        return $content;
    }
}